package com.bj58.groupbuy.action.service.impl;

import java.util.List;

import com.bj58.groupbuy.action.db.CommonDao;
import com.bj58.groupbuy.action.db.DBConfig;
import com.bj58.groupbuy.action.model.IRSubMailVo;
import com.bj58.groupbuy.action.service.IRSubMailService;
import com.bj58.groupbuy.service.impl.BaseService;
import com.bj58.groupbuy.wf.page.Paginate;

public class IRSubMailServiceImpl extends BaseService<IRSubMailVo> implements IRSubMailService {
	private CommonDao comDao = new CommonDao();

	@Override
	public List<IRSubMailVo> getListByUserId(int userId) throws Exception {
		List<IRSubMailVo> rsList = getGenericDao().find(IRSubMailVo.class, "*", "userId="+userId, "id");
		if( null != rsList  && !rsList.isEmpty())
			return rsList;
		
		return null;
	}

	@Override
	public Paginate<IRSubMailVo> getSubListByPage(int pageIndex, int pageSize,
			String where) throws Exception {
		return getGenericDao().findForPage(IRSubMailVo.class, where, "*", pageIndex, pageSize, "id desc");
	}

	@Override
	public int updateVo(IRSubMailVo vo)throws Exception {
		return comDao.updateByVo("ir_subemail", "id="+vo.getId(), IRSubMailVo.class, vo, DBConfig.db_68_bi_sys.getIntType());
		
	}

	@Override
	public IRSubMailVo findOneById(int id) throws Exception {
		String searchSql = "select * from ir_subemail  where id= "+id;
		List<IRSubMailVo> rsList = comDao.getAllColsByVo(searchSql, IRSubMailVo.class, DBConfig.db_68_bi_sys.getIntType());
		if(rsList.isEmpty() || null == rsList){
			return null;
		}
		return rsList.get(0);
	}

	@Override
	public List<IRSubMailVo> getAllToSendList() throws Exception {
		List<IRSubMailVo> rsList = getGenericDao().find(IRSubMailVo.class, "*", "state=1", "id");
		if( null != rsList  && !rsList.isEmpty())
			return rsList;
		
		return null;
	}
}
